﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using COFE.Core.Filter;
using System.Drawing;
using COFE.Core;
using COFE.Core.Utils;

namespace COFE.Core.EntryType
{
    public interface IEntryTypeDictionary
    {
        IEntryTypeInfo this[Guid Id] { get; }
        IEntryTypeInfo this[IFileSystemInfo entry] { get; }

        IEntryTypeIconExtractor IconExtractor { get; }
        IEntryFilterGenerator FilterGenerator { get; }
    }

    public static class IEntryTypeDictionaryExtension
    {
        public static IEntryTypeInfo CreateEti(this IEntryTypeDictionary etDic, IFileSystemInfo entry)
        {
            var filters = etDic.FilterGenerator.GenerateFilters(entry);
            if (entry is IFileInfo)
            {
                string fileType, mimeType;
                string ext = COFEPath.GetExtension(entry.Name);
                RegistryUtils.GetTypeInformation(ext, out fileType, out mimeType);
                if (String.IsNullOrEmpty(fileType))
                    fileType = RegistryUtils.GetFileDescription();
                return new EntryTypeInfo(filters, fileType, mimeType);
            }
            else
            {
                return new EntryTypeInfo(filters, RegistryUtils.GetDirectoryDescription(), null);
            }
        }
    }
}
